<template>
  <div class="container">
    <van-list
      v-model="loading"
      :finished="finished"
      @load="onLoad"
    >
      <van-cell
        v-for="(item, key) in list"
        v-bind:key="key"
        :title="item.title"
        is-link
        :to="'/help/view/'+item.id"
      />
    </van-list>
  </div>
</template>
<script>
import { Cell, List } from 'vant'

export default {
  components: {
    [Cell.name]: Cell,
    [List.name]: List
  },
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      count: 0,
      show: true,
      visible: false,
      meta: {
        totalCount: 0,
        pageCount: 0,
        currentPage: 0,
        perPage: 0
      }
    }
  },

  methods: {
    onLoad () {
      let cid = this.$route.params.id
      let page = this.meta.currentPage + 1
      this.axios
        .get('/assist/default/' + cid, {
          params: { page: page },
          headers: { FastMode: true }
        })
        .then(response => {
          let data = response.data
          let itemCount = data.items.length
          if (itemCount > 0) {
            this.list = this.list.concat(data.items)
          }
          this.meta = data.meta
          this.loading = false
          if (this.meta.pageCount <= this.meta.currentPage || itemCount <= 0) {
            this.finished = true
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    }
  }
}
</script>
